import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:wk_robot2/app/modules/componentview/controllers/MineViewController.dart';
import 'package:wk_robot2/app/utils/CommonUtil.dart';

import '../../../routes/app_pages.dart';
import '../../../style/app_colors.dart';
import '../../../widget/CommonWidgets.dart';
import '../../../widget/tips.dart';

class MineView extends GetView<MineViewController> {
  const MineView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.app_base_bgcolor_color,
      body: Stack(
        children: [
          Image.asset('assets/images/bg_home.webp',height: 470.h,fit: BoxFit.fill,width: Get.width),
          Obx(()=>Container(
            padding: EdgeInsets.only(left: 58.w,right: 58.h),
            child: ListView(
              children: [
                SizedBox(height: 44.h),
                GestureDetector(
                  onTap: () {
                    Get.toNamed(Routes.ABOUT_ACCOUNT);
                  },
                  child: Container(
                    child: Row(
                      children: [
                        Image.asset('assets/images/ic_avatar.webp',width: 96.w,height: 96.h,),
                        SizedBox(width: 35.w,),
                        Text('${controller.mUserNickName.value}',style: TextStyle(fontSize: 48.sp,fontWeight: FontWeight.w500, color: AppColors.Page_Title_Color))
                      ],
                    ),
                  ),
                )
                ,
                SizedBox(height: 30.h),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    GestureDetector(
                      onTap: () {
                        Get.toNamed(Routes.MINE_ROBOTS);
                      },
                      child: Container(
                        padding: EdgeInsets.all(10),
                        child: Text('我的机器人',style: TextStyle(fontSize: 30.sp,color: AppColors.Page_Title_Color),
                      )),
                    ),
                    CommonUtil.getMyRobotLists().length >= 2 ?
                    GestureDetector(
                      onTap: () {
                        Get.toNamed(Routes.MINE_ROBOTS);
                      },
                      child: Container(
                        padding: EdgeInsets.only(top: 9.h,bottom: 9.h,left: 23.w,right: 23.w),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(25)),
                            color: AppColors.MINE_ALL_ROBOT_CONTAINER_Color
                        ),
                        child: Text('查看全部',style: TextStyle(fontSize: 26.sp)),
                      ),
                    ): SizedBox()



                  ],
                ),
                SizedBox(height: 5.h),
                GestureDetector(
                  onTap: () {
                    if (controller.hasBindRobot.value) {
                      Get.toNamed(Routes.ROBOTS_DETAIL,parameters: {
                        'robotUserId': CommonUtil.getBltDeviceSN()
                      });
                    } else {
                      CommonUtil.bindDevices();
                    }

                  },
                  child: Stack(
                    children: [
                      Image.asset('assets/images/mine_bg_card.webp',width: 634.w,height: 440.h,),
                      controller.hasBindRobot.value ? Column(
                        children: [
                          SizedBox(height: 45.h),
                          Row(
                            children: [
                              SizedBox(width: 64.w),
                              Stack(
                                children: [
                                  Container(
                                    margin: EdgeInsets.only(top:45.h),
                                    child: CommonWidgets.getALine(width: 240),
                                  ),
                                  GestureDetector(
                                    onTap: () {
                                      Get.toNamed(Routes.ROBOTS_DETAIL,parameters: {
                                        'robotUserId': CommonUtil.getBltDeviceSN()
                                      });
                                    },
                                    child: Text('悟空机器人',style: TextStyle(fontSize: 48.sp),),
                                  )

                                ],
                              ),
                              SizedBox(width: 20.w),
                              Container(
                                padding: EdgeInsets.only(left: 20.w,right: 20.w,top: 4.h,bottom: 4.h),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.all(Radius.circular(20)),
                                  color: AppColors.robot_online_status_color,

                                ),
                                child: Text(controller.currentSelectedDevice.value.isOnline ? '在线':'离线',style: TextStyle(fontSize: 24.sp)),
                              ),


                            ],
                          ),
                          SizedBox(height: 20.h,),
                          Row(
                            children: [
                              SizedBox(width: 64.w),
                              Text(controller.dSN.value,style: TextStyle(fontSize: 30.sp,color: AppColors.Sub_Title_Color)),
                              SizedBox(width: 10.h,),
                              GestureDetector(
                                onTap: () {
                                  controller.copyTextToClipboard(controller.dSN.value);
                                },
                                child: Image.asset('assets/images/ic_copy.webp',width: 36.w,height: 36.h),
                              )


                            ],
                          ),
                          SizedBox(height: 56.h,),
                          Container(
                            margin: EdgeInsets.only(left: 107.w,right: 107.w),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                GestureDetector(
                                  onTap: () {
                                    Get.toNamed(Routes.MINE_WIFI_SETTING);
                                  },
                                  child: Column(
                                    children: [
                                      Image.asset('assets/images/ic_wifi_setting.webp',width: 80.w,height: 80.h),
                                      Text('Wi-Fi设置',style: TextStyle(fontSize: 22.sp,color: AppColors.line_right_character_color))
                                    ],
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () {

                                  },
                                  child: Column(
                                    children: [
                                      Image.asset('assets/images/ic_interactive.webp',width: 80.w,height: 80.h),
                                      Text('互动设置',style: TextStyle(fontSize: 22.sp,color: AppColors.line_right_character_color))
                                    ],
                                  ),
                                ),
                                GestureDetector(
                                  onTap: () {
                                    if (CommonUtil.getBltDeviceSN() == '') {
                                      return Tips.showToast('未找到当前机器人ID');
                                    }

                                    Get.toNamed(Routes.ROBOTS_DETAIL,parameters: {
                                      'robotUserId': CommonUtil.getBltDeviceSN()
                                    });
                                  },
                                  child: Column(
                                    children: [
                                      Image.asset('assets/images/ic_robot_infor.webp',width: 80.w,height: 80.h),
                                      Text('机器人信息',style: TextStyle(fontSize: 22.sp,color: AppColors.line_right_character_color))
                                    ],
                                  ),
                                )
                              ],
                            ),
                          )

                        ],
                      ) : Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              SizedBox(height: 30.h),
                              GestureDetector(
                                onTap: () {
                                  // Get.toNamed(Routes.ROBOTS_DETAIL);
                                  CommonUtil.bindDevices();
                                  // Get.toNamed(Routes.POWER_ONING);
                                },
                                child: Image.asset('assets/images/ic_default_my.webp',width: 380.w,height: 180.h,),
                              ),
                              GestureDetector(
                                onTap: () {
                                  // Get.toNamed(Routes.POWER_ONING);
                                  CommonUtil.bindDevices();
                                },
                                child: Image.asset('assets/images/ic_blind_black.webp',width: 66.w,height: 66.h,),
                              ),
                              SizedBox(height: 30.h),
                              Text('你还没绑定悟空机器人，请先绑定',style: TextStyle(fontSize: 26.sp,color: AppColors.newEditFieldHintText_color))

                            ],
                          )
                        ],
                      ),
                    ],
                  ),
                ),

                Container(
                  padding: EdgeInsets.all(20.w),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12.w),
                      color: Colors.white,
                      boxShadow: [
                        BoxShadow(
                          color: Colors.black.withOpacity(0.08), // 阴影颜色
                          spreadRadius: 2.w, // 阴影扩展半径
                          blurRadius: 7.w, // 阴影模糊半径
                          offset: Offset(0, 3), // 阴影偏移量（水平，垂直）
                        ),
                      ]
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Image.asset('assets/images/ic_feedback.webp',width: 60.w, height: 60.h),
                          SizedBox(width: 20.w),
                          Text('帮助与反馈',style: TextStyle(fontSize: 28.sp),),
                        ],
                      ),

                      Image.asset('assets/images/ic_arrow.webp',width: 30.w, height: 30.h),
                    ],
                  ),
                ),
                SizedBox(height: 24.h),
                Container(
                  padding: EdgeInsets.all(20.w),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12.w),
                      color: Colors.white,
                      boxShadow: [
                        BoxShadow(
                          color: Colors.black.withOpacity(0.05), // 阴影颜色
                          spreadRadius: 2.w, // 阴影扩展半径
                          blurRadius: 7.w, // 阴影模糊半径
                          offset: Offset(0, 3), // 阴影偏移量（水平，垂直）
                        ),
                      ]
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Image.asset('assets/images/ic_about.webp',width: 60.w, height: 60.h),
                          SizedBox(width: 20.w),
                          Text('关于',style: TextStyle(fontSize: 28.sp)),
                        ],
                      ),

                      Image.asset('assets/images/ic_arrow.webp',width: 30.w, height: 30.h),
                    ],
                  ),
                )


              ],
            ),
          ))
        ],
      ),
    );
  }
}
